<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
</head>
<body class="gray-bg">

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="form-content">
            <form id="user-form" class="form-horizontal">
                <!--<input type="hidden" id="deptId" name="deptId">-->
                <input type="hidden" id="parentId" value="100" name="parentId">
                <div class="row">
                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">编号：</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input type="text" name="params[userId]" class="form-control"/>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">会员名称：</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input type="text" name="userName" class="form-control" style="width: 316px;"/>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-4 col-md-offset-1">
                        <div class="form-group">
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="addBusiness()" shiro:hasPermission="system:user:addBusiness">
                <i class="fa fa-plus"></i> 新增会员
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="false"></table>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<!--<th:block th:include="include :: ztree-js"/>-->
<script th:src="@{/js/md5.min.js}"></script>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:user:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:user:remove')}]];
    var resetPwdFlag = [[${@permission.hasPermi('system:user:resetPwd')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "system/user";

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        queryUserList();
        queryDeptTree();
    });

    function queryUserList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "用户",
            columns: [{
                checkbox: true
            },
                {
                    field: 'userId',
                    title: '会员编号'
                },
                {
                    field: 'userName',
                    title: '会员名称',
                    sortable: true
                },
                {
                    field: 'amountSum',
                    title: '总金额'
                },
                {
                    field: 'clickFrzzingCash',
                    title: '刷单押金'
                },
                {
                    field: 'frzzingCash',
                    title: '提现中金额',
                },
                {
                    field: 'hasCashSum',
                    title: '已提现金额',
                },
                {
                    field: 'incomeCash',
                    title: '佣金',
                }, {
                    field: 'finalCash',
                    title: '可提现金额',
                }, {
                    field: 'firstSum',
                    title: '一级代理数',
                }, {
                    field: 'secondSum',
                    title: '二级代理数',
                }, {
                    field: 'thirdSum',
                    title: '三级代理数',
                },
                {
                    field: 'parentUserName',
                    title: '直接上级',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="resetPayPwd(\'' + row.userId + '\')"><i class="fa fa-edit"></i>重置支付密码</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="editBusiness(\'' + row.userId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.userId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + resetPwdFlag + '" href="#" onclick="resetPwd(\'' + row.userId + '\')"><i class="fa fa-key"></i>重置</a>');
                        actions.push('<a class="btn btn-success btn-xs ' + resetPwdFlag + '" href="#" onclick="addOrder(\'' + row.userId + '\')"><i class="fa fa-key"></i>上分</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

   function addOrder(userId) {
       layer.open({
           title: '请输入金额为' ,
           content: '<div style="color: black;"><label>请输入金额为:&nbsp;&nbsp;</label><input id="phoneCode" type="text" placeholder="请输入金额" style="width: 200px"></div>\n',
           btn: ['确定', '取消'],
           btn1: function(index, layero){
               var val = $('#phoneCode').val();
               if(val.trim()===''){
                   alert('请输入金额');
                   return false;
               }
               var url = ctx + "channel/channelUserInfo/resetSendPwd";
               var data = {"id": id,"code":val};
               $.operate.submit(url, "post", "json", data);
           },
           btn2: function(index, layero){
           }
       });
   }
    function resetPayPwd(id) {
        $.modal.confirm("确认要重置密码吗?", function () {
            var url = ctx + "channel/businessInfo/resetPayPwd";
            var data = {"id": id,"code":''};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function editBusiness(id) {
        var url = ctx + "system/user/editBusiness/" + id;
        $.modal.openTab("修改代商户", url);
    }

    function addBusiness() {
        var url = ctx + "system/user/addBusiness";
        $.modal.openTab("新增商户", url);
    }

    function querySubBusiness(id) {
        var url = ctx + "system/user/businessList/" + id;
        $.modal.openTab("查询下级商户", url);
    }
    function querySubScore(id) {
        var url = ctx + "system/user/scoreList/" + id;
        $.modal.openTab("查询下级代理", url);
    }
    function queryDeptTree() {
        var url = ctx + "system/dept/treeData";
        var options = {
            url: url,
            expandLevel: 1,
            onClick: zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#deptId").val(treeNode.id);
            $("#parentId").val(treeNode.pId);
            $.table.search();
        }
    }

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function () {
        queryDeptTree();
    });



    /* 用户管理-重置密码 */
    function resetPwd(userId) {
        $.modal.confirm("确认要重置密码吗?", function () {
            var url = prefix + '/resetPwd';
            var data = {"userId": userId, "password": md5("123456")};
            $.operate.submit(url, "post", "json", data);
        });
    }


    /* 用户状态显示 */
    function statusTools(row) {
        if (row.status == 1) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.userId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.userId + '\')"></i> ';
        }
    }

    /* 用户管理-停用 */
    function disable(userId) {
        $.modal.confirm("确认要停用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"userId": userId, "status": 1});
        })
    }

    /* 用户管理启用 */
    function enable(userId) {
        $.modal.confirm("确认要启用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"userId": userId, "status": 0});
        })
    }
</script>
</body>
<form id="importForm" enctype="multipart/form-data" class="mt20 mb10" style="display: none;">
    <div class="col-xs-offset-1">
        <input type="file" id="file" name="file"/>

        <div class="mt10 pt5">
            <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
            &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
                class="fa fa-file-excel-o"></i> 下载模板</a>
        </div>
        <font color="red" class="pull-left mt10">
            提示：仅允许导入“xls”或“xlsx”格式文件！
        </font>
    </div>
</form>
</html>